import 'package:flutter/material.dart';

/// @date 2020/08/14  14:04
/// @author 程志强
/// @des

class AnimatedDecoratedBox2 extends ImplicitlyAnimatedWidget {
  AnimatedDecoratedBox2({
    @required this.decoration,
    this.child,
    @required duration, // 正向动画执行时长
    Curve curve = Curves.linear, // 动画曲线
  }) : super(curve: curve, duration: duration);

  final BoxDecoration decoration;
  final Widget child;

  @override
  _AnimatedDecoratedBox1State createState() {
    return _AnimatedDecoratedBox1State();
  }
}

class _AnimatedDecoratedBox1State
    extends AnimatedWidgetBaseState<AnimatedDecoratedBox2> {
  DecorationTween _decoration;

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: _decoration.evaluate(animation),
      child: widget.child,
    );
  }

  @override
  void forEachTween(visitor) {
    _decoration = visitor(
        _decoration, widget.decoration, (value) => DecorationTween(begin: value));
  }
}
